<template>
  <head-top :loading="loading">
    <view class=" headtop">
      <u-search :clearabled="true" disabled :showAction="false" @click="searchs" placeholder="搜索商品" :animation="false"
        shape="round"></u-search>
      <b-divider></b-divider>
    </view>
    <view class="advImg">
      <u-swiper :list="list1"></u-swiper>
    </view>
    <view class="mt30">
      <b-tabs :list="[{ name: '推荐商品' }, { name: '发现好店' }]" @change="onTabs"></b-tabs>
    </view>
    <template v-if="tabIndexs == 0">
      <b-list></b-list>
    </template>
    <template v-else>
      <b-shop-list></b-shop-list>
    </template>
  
  </head-top>
</template>

<script setup lang="ts">
import { onLoad, onReachBottom, onShareAppMessage, onPageScroll, onShow } from "@dcloudio/uni-app";
import { ref, onMounted, getCurrentInstance, reactive, watch } from "vue";
import BDivider from '@/components/BDivider/index.vue'
import BMessage from '@/components/BMessage/BMessage.vue'
import BList from '@/components/BList/index.vue'
import BShopList from '@/components/BShopList/shopList.vue'
import BTabs from '@/components/BTabs/index.vue'
// const { proxy }: any = getCurrentInstance()
import { setApiData, sharefn, Scroll } from "@/hooks";

import QQMapWX from "@/common/lib/qqmap-wx-jssdk.min";
const qqmapsdk = new QQMapWX.QQMapWX({
  key: "UKZBZ-64JLQ-SWJ5A-GD5QR-4POM3-CEFL2",
});
const { setApi } = setApiData()
const { shareList } = sharefn()

const loading = ref<boolean>(true);
const tabIndexs = ref<number>(0)
const disabled = ref<boolean>(true);
const list1 = reactive([
  "https://img1.baidu.com/it/u=347034249,179256317&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800",
  "https://img1.baidu.com/it/u=347034249,179256317&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800",
  "https://img1.baidu.com/it/u=347034249,179256317&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800",
]);
// onPageScroll((res) => {
//   console.log(res, 'res')
// })
function onTabs(indexs, node) {
  uni.$emit('showLoading',true)
  setTimeout(()=>{
     tabIndexs.value = indexs
   uni.$emit('showLoading',false)
   },500)
}
function searchs() {
  uni.navigateTo({
    url: '/pages/search/search'
  })
}

function getAuthorizeInfo() {
  uni.authorize({
    scope: "scope.userLocation",
    success() {
      // 允许授权
      getlaction()
    },
    fail() {
      // 拒绝授权
    },
  });
}
function getlaction() {
  uni.getLocation({
    type: "gcj02",
    success(res) {
      console.log(res, 'res')
    },
    fail(err) {
      console.log(err, 'err')
    }
  });
}
const sublime = (async () => {
  //   setApi({  常规请求
  //   title: '测试接口',
  //   name: 'supplier_shop_option',
  //   param: [{ id: 111111 }]
  // }).then((e)=>{
  //   console.log(e,'e')
  // })
  //  博主自己封装的习惯使用 async/await  
     uni.$emit('showLoading',true)
   setTimeout(()=>{
   uni.$emit('showLoading',false)
   },2000)

  const result = await setApi({
    title: '测试接口',
    name: 'supplier_shop_option',
    param: [{ id: 111111 }]
  })
  console.log(result, 'res')

  uni.navigateTo({
    url: '/pages/demo/demo'
  })
})
// function sublime() {
//   //  uni.$emit('showLoading',true)
//   //  setTimeout(()=>{
//   //  uni.$emit('showLoading',false)
//   //  },2000)
//   // msg_.value.show({ text: '我是消息弹窗' })
//   // proxy.showMsg.show({ text: 'hahaha' })


// }
// const { top } = Scroll()
// watch(top, (val) => {
//   console.log(val, 'val')
// })
onLoad(() => {
  setTimeout(() => {
    loading.value = false;
    console.log(333)
  }, 3000);
  shareList.path = '/pages/shop/shop?id=3'
});
onShow(() => {
  // #ifdef MP-WEIXIN
  getAuthorizeInfo()
  // #endif
})
onShareAppMessage((e: any) => { })
onReachBottom(() => {
  console.log('到底；了。。。。')
})

</script>

<!-- <style lang="scss"  >
@import './index.scss';
</style> -->
